//
//  CommendDetailSectionView.m
//  meiyinxiang
//
//  Created by 媒印象 on 2018/1/10.
//  Copyright © 2018年 hbjApple. All rights reserved.
//

#import "CommendDetailSectionView.h"
#import "UIImage+Category.h"
@interface CommendDetailSectionView ()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageViwe;
@property (weak, nonatomic) IBOutlet UILabel *usernameLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *commentContentLabel;
@property (weak, nonatomic) IBOutlet UIButton *commentBtn;

@end
@implementation CommendDetailSectionView
+ (CommendDetailSectionView *)loadNib{
    UINib *nib = [UINib nibWithNibName:@"CommendDetailSectionView" bundle:[NSBundle mainBundle]];
    return [[nib instantiateWithOwner:nil options:nil] lastObject];
}
- (void)setViewModel:(CommentViewModel *)viewModel{
    _viewModel = viewModel;
    NSString *userId = [MYXMemberMdel sharedInstance].userinfo.userid;
    if ([userId isEqualToString:viewModel.user_id] || [userId isEqualToString:viewModel.rp_user_id]) {
        self.commentBtn.hidden = NO;
    }
    [self.iconImageViwe sd_setImageWithURL:[NSURL URLWithString:viewModel.userface] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        if (image) {
            self.iconImageViwe.image = [UIImage hbj_AvatarIcon:image size:image.size backgroundColor:[UIColor whiteColor]];
        }else{
            self.iconImageViwe.image = [UIImage hbj_AvatarIcon:[UIImage imageNamed:@"defual_luckyImg"] size:[UIImage imageNamed:@"defual_luckyImg"].size backgroundColor:[UIColor whiteColor]];

            //self.iconImageViwe.image = [UIImage imageNamed:@"defual_luckyImg"];
        }
    }];
    self.iconImageViwe.layer.cornerRadius = 22.5;
    self.iconImageViwe.contentMode = UIViewContentModeScaleAspectFill;
    self.iconImageViwe.clipsToBounds = YES;
    self.usernameLabel.text = viewModel.username;
    self.timeLabel.text = viewModel.create_time;
    self.commentContentLabel.text = viewModel.content;
}
//评论按钮
- (IBAction)commentBtn:(id)sender {
    [self.viewModel showCommentTextWithFinshBlock:^(BOOL isSucess) {
        
    }];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
